#include <stdio.h>
#include <math.h>
#include <stdlib.h>

//for io operation
#include <fcntl.h>
#include <sys/stat.h>

// beginning Linux Chapter 3 "File IO"
void WriteTest()
{
  if(write(1,"Here is some data\n",18) != 18)
    {
      write(2,"Error occur!\n",13);
    }
  //  exit(0);
}

void UserIDAndGroupID()
{
  printf("uid =  %d,gid =  %d\n",getuid(),getgid());
}

void CopyFile()
{
  char c;
  int infile,outfile;
  infile = open("main.c",O_RDONLY);
  outfile = open("../output/file.out",O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);

  while(read(infile,&c,1) == 1)
    write(outfile,&c,1);
  printf("Copy File Successfully\n");
}

int main(int argc,char **argv)
{
  UserIDAndGroupID();
  WriteTest();
  CopyFile();
  return 0;
}
